/** * This file has all javascript functions that address inventory alerts * requirements. * @author Sapient **/ /* Namespace setup */ if (typeof tjx == "undefined") { var tjx = {}; } if (typeof tjx.module == "undefined") { tjx['module'] = {}; } if (typeof tjx.module.account == "undefined") { tjx.module['account'] = {}; } jQuery(document).ready(function($) { tjx.module.account.loginregistration = { registrationErrorMessageMap: { "email_1" : "success", "email_2" : "email_error_format", "email_3" : "email_error_req", "email_4" : "email_error_exist", "confirmEmail_true" : "success", "confirmEmail_false" : "re-email_error_match", "password_4" : "pwd_error_format", "password_2" : "pwd_error_req", "password_3" : "pwd_error_length", "password_1" : "success", "confirmPassword_1" : "confpwd_error_format", "confirmPassword_2" : "pwd_confpwd_notmatch", "confirmPassword_3" : "success", "zipcode_1" : "success", "zipcode_2" : "zip_error", "zipcode_3" : "zip_error_format", "secretQuestion_true" : "success", "secretQuestion_false" : "secretselect_error", "secretAnswer_1" : "success", "secretAnswer_2" : "secretans_error", "termsOfUse_true" : "success", "termsOfUse_false" : "termsofuse_error_req" }, loginErrorMessageMap: { "email_1" : "success", "email_2" : "email_login_error_format", "email_3" : "email_login_error_req", "password_1" : "success", "password_2" : "pwd_login_error_req", "password_3" : "success", "password_4" : "success" }, fieldLabelMappings : { "email": "email", "confirmEmail": "re-email", "password": "newpwd", "confirmPassword": "confpassword", "zipcode": "zipcode", "secretQuestion": "secretselect", "secretAnswer": "secretans", "termsOfUse": "termsOfUse", "login.email": "log", "login.password": "pwd" }, init: function() { var authflag="acctpref"; if( authflag == "authfail" ){ $(".login .errorMessageContainer").show(); $(".login .errorMessageContainer #email_error_authenticate").show(); } var lockdown=""; if( lockdown == "true" ){ $(".login .errorMessageContainer").show(); $(".login .errorMessageContainer #email_error_lockdown").show(); } this.email = $('#registerform #email'); this.confirmEmail = $('#registerform #re-email'); this.password = $('#registerform #newpwd'); this.confirmPassword = $('#registerform #confpassword'); this.zipcode = $('#registerform #zipcode'); this.secretQuestion = $('#registerform #secretselect'); this.secretAnswer = $('#registerform #secretans'); this.termsOfUse = $('#registerform #termsOfUse')[0]; this.login = {}; this.login.email = $('.login #log'); this.login.password = $('.login #pwd'); regModuleObj = this; $('.login #signin').click(function( event ){ $(".login label").removeClass("errorIcon"); $(".login .errorMessageContainer ul li").hide(); $(".login .errorMessageContainer").hide(); var loginObj = regModuleObj.login; validFlag = {}; var sanitizedEmail = replaceCharacters("'","", loginObj.email.val()); loginObj.email.val(sanitizedEmail); validFlag.email = validateEmail( sanitizedEmail ); validFlag.password = validatePassword( loginObj.password.val() ); var errorMessageMapping = regModuleObj.handleValidationErrors( validFlag, regModuleObj.loginErrorMessageMap ); var failureFlag = false; $.each(errorMessageMapping, function(key, val){ if(val != "success") { failureFlag = true; $(".login .errorMessageContainer").show(); $(".login .errorMessageContainer #" + val).show(); $(".login label[for=" + regModuleObj.fieldLabelMappings["login." + key] + "]").addClass(errorIcon) } }); return !failureFlag ; }); $('#registerform #submit').click(function(event){ $(".register #errorMessageRegister ul li").hide(); $(".register #errorMessageRegister").hide(); $(".register label").removeClass("errorIcon"); event.preventDefault(); validFlag = {}; validFlag.email = validateEmail( regModuleObj.email.val() ); //if email format is valid check if the user is already registered if( validFlag.email == 1 && regModuleObj.checkUserExists() ) { //set the email flag and this will be dealt with by the handler validFlag.email = 4; } validFlag.confirmEmail = validateConfirmationEmail( regModuleObj.email.val() , regModuleObj.confirmEmail.val() ); validFlag.password = validatePassword( regModuleObj.password.val() ); validFlag.confirmPassword = validateConfirmationPassword( regModuleObj.password.val(), regModuleObj.confirmPassword.val() ); validFlag.zipcode = validateZipCode( regModuleObj.zipcode.val() ); validFlag.secretQuestion = validateDropdown( $.trim( regModuleObj.secretQuestion.val() ) ); validFlag.secretAnswer = validateSecretAnswer( $.trim( regModuleObj.secretAnswer.val() ) ); validFlag.termsOfUse = regModuleObj.termsOfUse.checked; var errorMessageMapping = regModuleObj.handleValidationErrors( validFlag, regModuleObj.registrationErrorMessageMap ); var failureFlag = false; $.each(errorMessageMapping, function(key, val){ if(val != "success") { failureFlag = true; $(".register #errorMessageRegister").show(); $(".register #" + val).show(); $(".register label[for=" + regModuleObj.fieldLabelMappings[key] + "]").addClass(errorIcon); } }); if( failureFlag === false) { regModuleObj.registerUser({ "newpwd": regModuleObj.password.val(), "email": regModuleObj.email.val(), "remail": regModuleObj.confirmEmail.val(), "zipcode": regModuleObj.zipcode.val(), "secretselect": regModuleObj.secretQuestion.val(), "secretans": replaceCharacters("|","",regModuleObj.secretAnswer.val()) }); return true; } else { return false; } }); $('#registerform #Loading').hide(); $('#registerform #UserLoading').hide(); }, checkUserExists: function() { var returnCode = false; jQuery('#UserLoading').show(); var sanitizedEmail = replaceCharacters("'","", regModuleObj.email.val()); jQuery.ajax({ type: "POST", async: false, url: "https://www.marshallsonline.com/wp-content/tjx-commons/request-handlers/tjx-usercheck.php", data: {"email": sanitizedEmail}, datatype: "html", success: function(response){ var msg=""; //jQuery('#checktext').fadeOut(); $("#errorMessageRegister").hide(); setTimeout("ajaxOnComplete('submittext', '')", 800); if(response=="Email address already registered"){ returnCode = true; } } }); return returnCode; }, handleValidationErrors: function( validFlag, errorMessageMap ) { var errorListitems = {}; $.each(validFlag, function(key, val){ errorListitems[key] = errorMessageMap[key + "_" + val]; }); return errorListitems; }, registerUser: function( params ) { //var datastring = "newpwd="+ str + "&email=" + email + "&remail=" + remail + "&zipcode=" + zipcode + "&secretselect=" + secretselect + "&secretans=" + secretans; jQuery('#Loading').show(); jQuery.ajax({ type: "POST", url: "https://www.marshallsonline.com/wp-content/tjx-commons/request-handlers/tjx-registerprocess.php", data: params, datatype:"html", success: function(response){ s1 = s_gi("tjxmarshalls"); s1.linkTrackVars="prop10,prop11,prop12,events,eVar7,eVar13"; s1.linkTrackEvents = "event1"; s1.events = "event1"; var s_code1=s1.tl(); if(s_code1) document.write(s_code1); jQuery('#submittext').fadeOut(); setTimeout("ajaxOnComplete('submittext', '"+escape(response)+"')", 800); //redirect to notification preferences page sanitizedEmail = replaceCharacters("'","",params.email); jQuery.ajax({ type: "POST", url: "https://www.marshallsonline.com/wp-login.php", data: {"log": sanitizedEmail, "pwd": params.newpwd}, datatype:"html", success: function(response){ //jQuery('#submittext').fadeOut(); //setTimeout("ajaxOnComplete('submittext', '"+escape(response)+"')", 800); top.location.href="https://www.marshallsonline.com/account-preferences?register_event=true"; } }); } }); }, loginUser: function() { } }; tjx.module.account.accountInfo = { fireRSSEvent: function(category) { s1 = s_gi("tjxmarshalls"); s1.linkTrackVars="prop11,prop12,eVar13,events,eVar7"; s1.prop11 = category.replace("'", ""); s1.prop12 = "RSS"; s1.eVar13 = "RSS (Preferences)"; s.eVar7="In"; var s_code1=s1.tl(); if(s_code1) document.write(s_code1); }, fireFacebookEvent: function() { s1 = s_gi("tjxmarshalls"); s1.prop12 = "Facebook";s1.eVar13 = "Facebook (Preferences)";s1.eVar7 = "In"; s1.linkTrackVars="prop10,prop11,prop12,events,eVar7,eVar13"; s1.linkTrackEvents = ""; s1.events = ""; var s_code1=s1.tl(); if(s_code1) document.write(s_code1); }, fireTwitterEvent: function() { s1 = s_gi("tjxmarshalls"); s1.prop12 = "Twitter";s1.eVar13 = "Twitter (Preferences)";s1.eVar7 = "In"; s1.linkTrackVars="prop10,prop11,prop12,events,eVar7,eVar13"; s1.linkTrackEvents = ""; s1.events = ""; var s_code1=s1.tl(); if(s_code1) document.write(s_code1); }, fireEmailPrefEvent: function() { checkboxes = $('.emailLeftCol input[type="checkbox"]'); if(false) labels = $('.emailLeftCol label.marginTop2'); else labels = $('.emailLeftCol label.marginLeft30') var arrSelectedCat = new Array(); selectedCategories = ''; count = 0; for( i=0; i< checkboxes.length; i++) { if(checkboxes[i].checked) { currentCat = labels[i].innerHTML.replace("'", ""); currentCat = currentCat.replace("&", "-"); currentCat = currentCat.replace(/ /g, ""); arrSelectedCat[count++] = currentCat.substr(0, 10); } } selectedCategories = arrSelectedCat.join("|") ; s1 = s_gi("tjxmarshalls"); s1.linkTrackVars="prop10,prop12,eVar13,events"; s1.prop12 = "Email"; s1.eVar13 = "Email (Preferences)"; s.eVar7="In"; s1.prop10 = selectedCategories; var s_code1=s1.tl(); if(s_code1) document.write(s_code1); } }; }); var errorIcon="errorIcon"; // Wrapper to email validation function validateEmail(email){ if(email.length != 0) { if(isValidEmailAddress(jQuery.trim(email))) { return 1; } else { return 2; } } else { return 3; } }// end of validateEmail function validateConfirmationEmail(email, remail){ if(remail.length== 0) { return false; } if ( jQuery.trim(email) != jQuery.trim(remail)) { return false; } return true; } function validateConfirmationPassword(newpwd,confpassword){ if(confpassword.length == 0) { return 1; } else if ( jQuery.trim(newpwd) != jQuery.trim(confpassword)) { return 2; } else {return 3;} } /* This function is used to hold reponse to add a fadeIn response effect to the page */ function ajaxOnComplete(id, response) { jQuery('#Loading').hide(); jQuery('#UserLoading').hide(); jQuery('#'+id).html(unescape(response)); jQuery('#'+id).fadeIn(); } //finishAjax function validateZipCode(zip) { if(zip.length==0) { return 2; } else if (zip.length != 5) { return 3; } else if (isNaN(zip)) { return 3; } else if (Number(zip) <= 0 ) { return 3; } else {return 1;} } function validateSecretAnswer(answer) { if(answer.length==0){ return 2; }else{ return 1; } } function validateDropdown(secretselect){ if(secretselect=="Select one") return false; else return true; } function validatePassword(str){ if (str.length==0) { return 2; } if ((str.length >= 8 && str.length <= 16)) { // do something }else{ return 3; } if (((str.search(/[!,#,$,%,&,*,+,-,.,?,@,^,_,~]/)!= -1) && (str.search(/[A-Z]+/)!= -1) && (str.search(/[a-z]+/)!= -1)) || ((str.search(/[!,#,$,%,&,*,+,-,.,?,@,^,_,~]/)!= -1) && (str.search(/[0-9]+/)!= -1) && ( (str.search(/[A-Z]+/)!= -1) || (str.search(/[a-z]+/)!= -1))) || (( (str.search(/[A-Z]+/)!= -1) && (str.search(/[a-z]+/)!= -1)) && (str.search(/[0-9]+/)!= -1))) { return 1; } return 4; }// end of validatePassword // Email validation function isValidEmailAddress(emailAddress) { /*var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i); */ var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i; //Apostrophe email handling emailAddress=replaceCharacters("'","",emailAddress); if (emailAddress.search(emailRegEx) == -1) return false; else return true; } /* This functiontakes original string and returns a new string with certain incharacter/string with a replaced character of choice*/ function replaceCharacters(inChar,replacewithChar,origString) { var newString = origString.split(inChar); newString = newString.join(replacewithChar); return(newString); } function ValidatePrice(price) { var intCt; var blnResult = true; if (price.length <= 0) { blnResult = false; } else if (price.length > 9) { blnResult = false; } else if (price.indexOf(".") == 0) { blnResult = false; } else if ((price.indexOf('.')>0) &&(price.substring(0,price.indexOf('.')).length >6 )) { blnResult = false; } else { var phoneRE = /^\d+([\.]\d\d)?$/; if (price.match(phoneRE)) blnResult = true; else blnResult = false; } return blnResult; }