//Use $j or jQuery to reference the jQuery library outside of document.ready(). May continue to use $ for jQuery inside // document.ready() //The use of $ has been relinquished to bootstrap (see cssolayout.jsp) var userSecQAPick = new Object; var totalSecQAEachUser = 4; var USA = "United States of America"; // 2014-0919 var currentHistPage; var currentUpcomePage; var appReceiptNum; var httpSessionIgnoreDialog = true; function setHTTPSessionVariable(url, params, successCallback, errorCallback) { $.ajax({ success : successCallback, error : errorCallback, data : params, url : url, type : 'GET', cache : false, async: false, dataType : 'json', xhrFields: { withCredentials: true } }); } function setHTTPSessionVariableValue(value_) { setHTTPSessionVariable(location.origin + '/casestatus/AjaxSetSessionVariable.do', { ajaxVariableName : 'ajaxVariableName', ajaxVariableValue : value_ }, function(data, status, jqXhr) { var dataJson = null; try { dataJson = data; if(value_ == 'true' && data.status2 == 'success2' ){ httpSessionIgnoreDialog = true; }else{ httpSessionIgnoreDialog = false; } } catch(e) { console.log("dataJson = JSON.parse(data); = " + e); httpSessionIgnoreDialog = false; } }, function(jqXhr, textStatus, errorMessage) { httpSessionIgnoreDialog = false; } ); return httpSessionIgnoreDialog; } function getHTTPSessionVariable(url, params, successCallback, errorCallback) { $.ajax({ success : successCallback, error : errorCallback, data : params, url : url, type : 'GET', cache : false, async: false, dataType : 'json', xhrFields: { withCredentials: true } }); } function getHTTPSessionVariableValue() { getHTTPSessionVariable(location.origin + '/casestatus/AjaxGetSessionVariable.do', { ajaxVariableName : 'ajaxVariableName' }, function(data, status, jqXhr) { var dataJson = null; try { dataJson = data; if(dataJson.result2 == 'true' ){ httpSessionIgnoreDialog = true; }else{ httpSessionIgnoreDialog = false; } } catch(e) { httpSessionIgnoreDialog = false; } }, function(jqXhr, textStatus, errorMessage) { httpSessionIgnoreDialog = false; } ); return httpSessionIgnoreDialog; } function buildReceiptPrefixPattern(){ var receiptPrefixPattern=""; var counter=0; //receiptPrefixMap is set in validationmessages.jsp for (var mapKey in receiptPrefixMap){ if (counter > 0){ receiptPrefixPattern += "|"; } receiptPrefixPattern += receiptPrefixMap[mapKey]; ++counter; } return receiptPrefixPattern; } jQuery(document).ready(function($){ $( "form" ).submit(function() { setHTTPSessionVariableValue('false'); return true; } ); $("#skipper").click(function () { //Global variable mainContentId is set in cssolayout.jsp $('#' + mainContentId).attr('tabIndex', -1).focus(); }); //last minute change to make password field blank when the login page is displayed if (existsInDom($('#password')) && existsInDom($('#loginBtn'))){ $('#password').val(''); } $("#applicant_cust_div").keypress(function(event) { if (13==event.keyCode){ $("#applicant-customer").trigger( "click" ); event.preventDefault() } }); $("#applicant_rep_div").keypress(function(event) { if (13==event.keyCode){ $("#customer_representative").trigger( "click" ); event.preventDefault() } }); function hasTwoIdenticalConsecutiveChars(value){ var check = false; for (var i = 0; i < value.length - 2; i++) { if ((value.substring(i,i+1)) == (value.substring(i+1, i+2))) { if ((value.substring(i+1, i+2)) == (value.substring(i+2, i+3))) { check = true; break; } // end if } // end if } // end for return check; } function isUndefined(object){ return typeof object === 'undefined'; } var alertBox = new alertDialog( {my:'left+40 top+10', at:'center-200', of:window, collision:'flip' }, '55%', '', "popupDialogArea", okButtonCaption, function(){ return true; }, closeButtonCaption ); page.init(); $("#country").change(function () { page.setState(); }); $.validator.addMethod( "validReceiptNumber", function (value, element) { var pattern = new RegExp("^(" + buildReceiptPrefixPattern() + ")(\\*|\\d)\\d{9}$"); return this.optional(element) || pattern.test(value.toUpperCase()); } ); $.validator.addMethod( "validMobilePhone", function (value, element) { // A valid phone number is either 10 digits as in 2025551212 // or 12 characters (3 digits-3 digits-4 digits) as in 202-555-1212. var pattern = /^\d{10}|\d{3}\-\d{3}\-\d{4}$/; return this.optional(element) || pattern.test(value); } ); $.validator.addMethod( "validPostalCode", function (value, element) { // A valid US zip code is either five digits or 'five digits-four digits' var pattern = /^\d{5}(?:\-\d{4})?$/; var country = $("#country :selected").text(); return this.optional(element) || (country == USA && pattern.test(value)) || country != USA ; } ); $.validator.addMethod( "userNameLength", function (value, element) { var userNameRules = $("#userNameRules").val(); if (isUndefined(userNameRules) || userNameRules.indexOf("userNameLength") == -1){ return true; } else { return this.optional(element) || (value.length > 7 && value.length < 15) ; } } ); $.validator.addMethod( "userNameDollarSign", function (value, element) { var userNameRules = $("#userNameRules").val(); if (isUndefined(userNameRules) || userNameRules.indexOf("userNameDollarSign") == -1){ return true; } else { return this.optional(element) || value.indexOf("$") == -1; } } ); $.validator.addMethod( "passwordLength", function (value, element) { var passwordRules = $("#passwordRules").val(); if (isUndefined(passwordRules) || passwordRules.indexOf("passwordLength") == -1){ return true; } else { return this.optional(element) || (value.length > 7 && value.length < 15); } } ); $.validator.addMethod( "passwordDollarSign", function (value, element) { var passwordRules = $("#passwordRules").val(); if (isUndefined(passwordRules) || passwordRules.indexOf("passwordDollarSign") == -1){ return true; } else { return this.optional(element) || value.indexOf("$") == -1; } } ); $.validator.addMethod( "passwordUpperCase", function (value, element) { var passwordRules = $("#passwordRules").val(); var pattern = /[A-Z]/; if (isUndefined(passwordRules) || passwordRules.indexOf("passwordUpperCase") == -1){ return true; } else { return this.optional(element) || pattern.test(value); } } ); $.validator.addMethod( "passwordLowerCase", function (value, element) { var passwordRules = $("#passwordRules").val(); var pattern = /[a-z]/; if (isUndefined(passwordRules) || passwordRules.indexOf("passwordLowerCase") == -1){ return true; } else { return this.optional(element) || pattern.test(value); } } ); $.validator.addMethod( "passwordUserName", function (value, element) { var username = $("#username").val(); var passwordRules = $("#passwordRules").val(); // Enforce this constraint only on the signup page (step 3 of signup) if (isUndefined(passwordRules) || passwordRules.indexOf("passwordUserName") == -1){ return true; } else { return this.optional(element) || value.toLowerCase().indexOf(username.toLowerCase()) == -1; } } ); $.validator.addMethod( "passwordNumber", function (value, element) { var pattern = /\d/; var passwordRules = $("#passwordRules").val(); if (isUndefined(passwordRules) || passwordRules.indexOf("passwordNumber") == -1){ return true; } else { return this.optional(element) || pattern.test(value); } } ); $.validator.addMethod( "passwordPassword", function (value, element) { var passwordRules = $("#passwordRules").val(); if (isUndefined(passwordRules) || passwordRules.indexOf("passwordNumber") == -1){ return true; } else { return this.optional(element) || value.toLowerCase().indexOf('password') == -1; } } ); $.validator.addMethod( "passwordConsecutiveChars", function (value, element) { var passwordRules = $("#passwordRules").val(); if (isUndefined(passwordRules) || passwordRules.indexOf("passwordNumber") == -1){ return true; } else { return this.optional(element) || !hasTwoIdenticalConsecutiveChars(value); } } ); $.validator.addMethod( "passwordConfirmationMatch", function (value, element) { var passwordRules = $("#passwordRules").val(); if (isUndefined(passwordRules) || passwordRules.indexOf("passwordConfirmationMatch") == -1){ return true; } else { return this.optional(element) || (value == $("#password").val() || value == $("#newPassword").val()); } } ); // Added this to prevent a form with validation errors from being submitted in Firefox // when the user presses Enter in an text field $("form :input[type=text]").keypress(function(e){ if (e.which == 13){ e.preventDefault(); return false; } }); /* helper text */ $( '#receiptNumberHelperAnchor' ).click(function() { alertBox.title= receiptNumberHelp; alertBox.open( receiptNumberHelperText ); return false; }); $( '#passwordReqHelperAnchor' ).click(function() { alertBox.title= passwordHelpTitle; alertBox.open( passwordReqHelperText ); return false; }); $( '#usernameReqHelperAnchor' ).click(function() { alertBox.title= userNameHelpTitle; alertBox.open( usernameReqHelperText ); return false; }); // completed $('#prevHistPageBtn').click(function() { currentHistPage = (currentHistPage > 0) ? currentHistPage-1 : currentHistPage; $('#completedActionsCurrentPage').val(currentHistPage); page.setCompletedActionsArea(); return false; }); $('#nextHistPageBtn').click(function() { currentHistPage = (currentHistPage < totalHistPages-1) ? currentHistPage+1 : currentHistPage; $('#completedActionsCurrentPage').val(currentHistPage); page.setCompletedActionsArea(); return false; }); // upcoming $('#prevUpcomePageBtn').click(function() { currentUpcomePage = (currentUpcomePage > 0) ? currentUpcomePage-1 : currentUpcomePage; $('#upcomingActionsCurrentPage').val(currentUpcomePage); page.setUpcomingActionsArea(); return false; }); $('#nextUpcomePageBtn').click(function() { currentUpcomePage = (currentUpcomePage < totalUpcomePages-1) ? currentUpcomePage+1 : currentUpcomePage; $('#upcomingActionsCurrentPage').val(currentUpcomePage); page.setUpcomingActionsArea(); return false; }); // security question option tags dynamic rendering $('#question1').change(function(){ userSecQAPick[1] = $('#question1').val(); page.setSecQuestionsOptions( 1 ); }); $('#question2').change(function(){ userSecQAPick[2] = $('#question2').val(); page.setSecQuestionsOptions( 2 ); }); $('#question3').change(function(){ userSecQAPick[3] = $('#question3').val(); page.setSecQuestionsOptions( 3 ); }); $('#question4').change(function(){ userSecQAPick[4] = $('#question4').val(); page.setSecQuestionsOptions( 4 ); }); $("#systemWarningLink").click(function () { var systemSecurityConfirm = new alertDialog( {my:'left+40 top-200', at:'center-200', of:window, collision:'flip' }, '55%', systemSecurityTitle, "popupDialogArea", okButtonCaption, function(){ return true; }, closeButtonCaption ); systemSecurityConfirm.open( systemSecurityWarning ); return false; }); $("#privacyStatementsAnchor").click(function () { alertBox.title= privacyActTitle; alertBox.open( privacyStatementsContentsJS ); return false; }); // prevent existing users to access profile or portfolio until they updated security Q and A $('.noActionUntilSecQAUpdated').click(function(e){ e.preventDefault(); }); $('#changeLocaleAnchor').click(function() { if (existsInDom($('#changeLocale'))){ $('#changeLocale').val(changeLangTo); } var receiptExistsinDom = existsInDom($('#receipt_number')); var appReceiptNumDefined = !isUndefined(appReceiptNum); if (receiptExistsinDom && appReceiptNumDefined ){ $('#receipt_number').val(appReceiptNum); } if (existsInDom($('form'))){ $("form").validate().cancelSubmit = true; $("form").submit(); } else { var tmpA = document.createElement('a'); tmpA.href = document.URL; var pathName = tmpA.pathname; var myuscis = 'casestatus/'; var myuscisAt = (pathName.toLowerCase()).lastIndexOf(myuscis); var dotDo = (pathName.toLowerCase()).lastIndexOf('.do'); var path = pathName.substring( myuscisAt + myuscis.length, dotDo ); var newUrl = (tmpA.href).replace(path,"changeLocale") + "?localeLang=" + changeLangTo + "&path=" + path; window.location.replace( newUrl ); } return false; }); }); function existsInDom(object){ if (object.length > 0){ return true; } return false; }; page = { init : function(){ this.setPageTitle(); if( existsInDom($j('#completedActionListDiv')) ) { this.setCompletedActionsArea(); } if( existsInDom($j('#upcomingActionListDiv'))) { this.setUpcomingActionsArea(); } if(existsInDom($j('#question1')) && !(typeof allSecQuestions === "undefined") && Object.size(allSecQuestions) > 0 ) { for(var i = 1; i <= totalSecQAEachUser; i++) { userSecQAPick[i] = ( $j('#question' + i).val() ) ? $j('#question' + i).val() : 0; } this.setSecQuestionsOptions( 0 ); } // set up pagination current page numbers if these values available in the hidden fields if($j('#completedActionsCurrentPage') != null && $j('#completedActionsCurrentPage').value != '' ) { currentHistPage = parseInt( $j('#completedActionsCurrentPage').val() ); } if($j('#upcomingActionsCurrentPage') != null && $j('#upcomingActionsCurrentPage').value != '' ) { currentUpcomePage = parseInt( $j('#upcomingActionsCurrentPage').val() ); } if($j('#changeLocale') != null ){ $j('#changeLocale').val( null ); } this.setState(); this.displayServerSideErrors(); }, setInitFocus: function(){ this.setFocus('.initial-focus'); }, setUsernameFocus: function(){ $('#username').val(''); this.setFocus('#username'); }, setPasswordFocus: function(){ $('#password').val(''); this.setFocus('#password'); }, setReceiptFocus: function(){ $('#receipt_number').val(''); this.setFocus('#receipt_number'); }, setEmailFocus: function(){ $('#email').val(''); this.setFocus('#email'); }, setNewPasswordFocus: function(){ $('#newPassword').val(''); $('#confirmPassword').val(''); this.setFocus('#newPassword'); }, setNewPasswordConfFocus: function(){ $('#confirmPassword').val(''); this.setFocus('#confirmPassword'); }, scrollTo: function(objectId){ $j('body').scrollTo("#" + objectId); }, setFocus: function(selector){ $j(selector).focus(); }, serverSideErrorFound: function(){ errorRegion = $j("#formErrorMessages").html(); // The content of the Error region (div with Id formErrorMessages) is null in IE when there are no errors, // but in Firefox the length of this area is greater than zero (8 spaces) when there are no errors. //Therefore to determine whether there are any server side errors we need to check for two conditions: // the area being null for IE or the length of the area after being trimmed being zero for Firefox // Be aware that the Javascript function trim() doesn't work in IE 8. I (Leila) had to use the jquery function $.trim() // to trim the content of the error area. if (!errorRegion){ // Error region is null/undefined in IE when no errors return false; } else if ( $j.trim($j("#formErrorMessages").html()).length == 0 ){ // For Firefox when there is no error return false; } return true; }, setPageTitle: function(){ if (typeof pageTitle !== "undefined"){ document.title = appName + ' - ' + pageTitle; } }, disableArea : function(area){ $j("#" + area).prop("disabled", true); }, enableArea : function(area){ $j("#" + area).prop("disabled", false); }, setState: function(){ var country = $j.trim($j("#country :selected").text()); if (country == USA) { this.enableArea("state"); } else { $j('#state').val(""); this.disableArea("state"); } }, setCompletedActionsArea:function() { var markup = ''; $j('#completedActionListDiv').html( markup ); var d = document.getElementById("completedActionListDiv"); d.className = d.className + " .search-status-list" + " .search-status-list ul" + " .search-status-list ul li" + " .search-status-list ul li .date-sec" + " .search-status-list ul li .date-sec span" + " .search-status-list ul li .date-sec span.red" + " .search-status-list ul li .contant-sec" + " .search-status-list ul li .contant-sec p" + " .search-status-list ul li .contant-sec a" ; var tempPageNum = (currentHistPage + 1) / 1; markup = '' + tempPageNum + ''; $j('#currentPageNumInHist').html( markup ); markup = '' + totalHistPages + ''; $j('#totalPageNumInHist').html( markup ); }, setUpcomingActionsArea:function() { var markup = ''; $j('#upcomingActionListDiv').html( markup ); var d = document.getElementById("upcomingActionListDiv"); d.className = d.className + " .search-status-list" + " .search-status-list ul" + " .search-status-list ul li" + " .search-status-list ul li .date-sec" + " .search-status-list ul li .date-sec span" + " .search-status-list ul li .date-sec span.red" + " .search-status-list ul li .contant-sec" + " .search-status-list ul li .contant-sec p" + " .search-status-list ul li .contant-sec p.upcoming" + " .search-status-list ul li .contant-sec a" ; var tempPageNum = (currentUpcomePage + 1) / 1; markup = '' + tempPageNum + ''; $j('#currentPageNumInUpcome').html( markup ); markup = '' + totalUpcomePages + ''; $j('#totalPageNumInUpcome').html( markup ); }, setSecQuestionsOptions: function( activeCtrlIdx ) { userSecQAPick[activeCtrlIdx] = (activeCtrlIdx) ? $j('#question' + activeCtrlIdx).val() : 0; for( var targetCtrlIdx = 1; targetCtrlIdx <= totalSecQAEachUser; targetCtrlIdx++ ) { var htmlStr = '\n'; $j('#question'+targetCtrlIdx).html( htmlStr ); if( userSecQAPick[targetCtrlIdx] ) { $j('#question'+targetCtrlIdx).val( userSecQAPick[targetCtrlIdx] ); } } }, displayServerSideErrors: (getHTTPSessionVariableValue() && httpSessionIgnoreDialog) ? function() { } : function(){ if (this.serverSideErrorFound()){ var serverSideErrorBox = new alertDialog( {my:'left+40 top+10', at:'center-200', of:window, collision:'flip' }, '55%', '', "popupDialogArea", okButtonCaption, function(){ setHTTPSessionVariableValue('true'); var mes = $j("#formErrorMessages").text(); if(( mes.indexOf("User name is required")) >= 0 || (mes.indexOf("El nombre de usuario es obligatorio")) >= 0 || (mes.indexOf("User"))>= 0 || (mes.indexOf("Nombre de Usuario"))>= 0 || (mes.indexOf("Your login was invalid.")) >= 0 || (mes.indexOf("Su conexión era inválida.")) >= 0) { page.setUsernameFocus(); } else if((mes.indexOf("Please enter an application receipt number.")) >= 0 || (mes.indexOf("The application receipt number entered is invalid. Please check your receipt number and try again.")) >=0 || (mes.indexOf("Sírvase ingresar un número de recibo de la solicitud.")) >=0 || (mes.indexOf("El número de recibo de solicitud introducido no es válido. Por favor, compruebe su número de recibo de solicitud y vuelva a intentarlo.")) >=0) { page.setReceiptFocus(); } else if((mes.indexOf("Password is required") >= 0 && window.location.href.indexOf("changeLostPassword") < 0) || (mes.indexOf("La contraseña es obligatoria")) >= 0 || (mes.indexOf("Verifique su Nombre de Usuario o su Contraseña e inténtelo de nuevo.")) >= 0 || (mes.indexOf("Check your User Name and/or Password and try again.")) >= 0) { page.setPasswordFocus(); } else if((mes.indexOf("Email address is required")) >= 0 || (mes.indexOf("La dirección de correo electrónico es obligatoria")) >= 0 || (mes.indexOf("Email Address was not found."))>= 0 || (mes.indexOf("Enter a valid email address in the format: example@example.com"))>= 0 || (mes.indexOf("Ingrese una dirección de correo electrónico válida"))>= 0 ) { page.setEmailFocus(); } else if((mes.indexOf("Password must contain at least one upper case character")) >= 0 || (mes.indexOf("Password is required")) >= 0 || (mes.indexOf("Password must contain at least one number")) >= 0 || (mes.indexOf("Password must contain at least one lower case character"))>= 0 || (mes.indexOf("Password must be between 8 and 14 characters"))>= 0 || (mes.indexOf("Password cannot contain more than two consecutive identical characters"))>= 0 || (mes.indexOf("Your password must not contain the word 'password'"))>= 0 || (mes.indexOf("Password cannot contain the dollar sign"))>=0 || (mes.indexOf("Password was previously used. Choose another password"))>= 0 || (mes.indexOf("Password cannot contain your user name"))>= 0 || (mes.indexOf("La contraseña no puede tener su nombre de usuario"))>= 0 || (mes.indexOf("La contraseña no puede tener ningún símbolo de dinero"))>=0 || (mes.indexOf("Su contraseña no puede contener la palabra 'password'"))>= 0 || (mes.indexOf("Contraseña previamente usada. Seleccione otra contraseña"))>= 0 || (mes.indexOf("La contraseña debe tener al menos una letra mayúscula"))>= 0 || (mes.indexOf("La contraseña debe tener al menos una letra minúscula"))>= 0 || (mes.indexOf("La contraseña debe tener por lo menos un número"))>= 0 || (mes.indexOf("La contraseña debe tener entre 8 y 14 caracteres"))>= 0 || (mes.indexOf("La contraseña no puede tener más de dos caracteres idénticos consecutivos"))>= 0 ) { page.setNewPasswordFocus(); } else if((mes.indexOf("Password confirmation is required")) >= 0 || (mes.indexOf("Se requiere que confirme su contraseña")) >= 0 || (mes.indexOf("Password confirmation must match the password"))>= 0 || (mes.indexOf("La confirmación de contraseña debe coincidir con la contraseña"))>= 0 ) { page.setNewPasswordConfFocus(); } else{ page.setInitFocus(); } }, closeButtonCaption ); if(locale == "en_US" || locale == ""){ serverSideErrorBox.title= "Data Entry Errors"; }else{ serverSideErrorBox.title= "Errores de validaci\xF3n"; } serverSideErrorBox.open($j("#formErrorMessages").html()); } else { setHTTPSessionVariableValue('true'); } }, submit: function(){ $j("form").submit(); } }; function caseInfo( caseSelected, receiptNumber, trackingNumber, lastUpdated, formNumber, eMailAlertOn, smsAlertOn ) { this.caseSelected = caseSelected; this.receiptNumber = receiptNumber; this.trackingNumber = trackingNumber; this.lastUpdated = lastUpdated; this.formNumber = formNumber; this.eMailAlertOn = eMailAlertOn; this.smsAlertOn = smsAlertOn; return this; };