var uber = uber || {}; uber.reg = { init: function() { uber.reg.createListeners(); uber.reg.setState(); uber.reg.setFormTips(); }, createListeners: function() { // CLICKING REGISTER BUTTON $('#Register:not(.disabled)').click(function (e) { uber.reg.handleRegisterClick(); }); // KEYCODE CHANGE - RESET FORM $('#KeyCode').change(function (e) { $('#keytype').val(''); $('#dregion').hide(); $('#Region').val('').attr('allowblank', true); $('#dterms').addClass('hidden'); //$('#Terms').prop('checked', false).attr('allowblank', true); $('#pterms').hide(); }); // ************************************************************************* // // FORMTIPS // // ************************************************************************* $('body').on('focus', '[data-formtip]', function() { uber.reg.positionFormtip(this); }) $('body').on('blur', '[data-formtip]', function() { $('.formtip').removeClass('show'); }) $('body').on('keyup', '[data-formtip]', function(e) { // IGNORE TAB AND SHIFT KEYS if(e.keyCode != 9 && e.keyCode != 16) { $('.formtip').removeClass('show'); } }) $(window).resize(function() { var activefield = $('[data-formtip]:focus'); if(activefield.length > 0) { uber.reg.positionFormtip(activefield[0]) } else { // SHUFFLE FORMTIP OUT OF THE WAY IF CREATED WIDE, AND WINDOW RESIZES AFTER var formtip = $('.formtip'); if(formtip.length > 0) { formtip.css({ left: 0, width: 1 }) } } }) }, setState: function() { // HIDE ANY TERMS ELEMENTS $('#dterms').addClass('hidden'); $('#pterms').hide(); // HIDE ANY REGION ELEMENTS $('#dregion').hide(); $('#pregion').hide(); // IF BUSINESS, SHOW TERMS, WITH ERROR IF NECESSARY if ($('#ent').val() == '1') { $('#dterms').removeClass('hidden'); /* var Ts = $('#Terms').is(':checked'); if (!Ts) { $('#dterms .mockinput').addClass('fielderror'); $('#pterms').show(); } */ } // IF COMPLETE, SHOW REGION SELECTION, WITH ERROR IF NECESSARY if ($('#reg').val() == '1') { $('#dregion').show(); var Regions = $('#Region').find('option:selected').val(); if (Regions == '') { $('#Region').addClass('fielderror'); $('#pregion').show(); } } }, handleRegisterClick: function() { //console.log('REG CLICK'); var form = $('#signupform'); var formdata = wrjs.utils.form.getFormData(form); var isvalid = wrjs.utils.form.isFormValid(form); //console.log(isvalid, formdata); //$('p.fielderror').remove(); //$('input.fielderror').removeClass('fielderror'); var Key = $.trim($('#KeyCode').val()); var Email = $('#Email').val(); var ConfirmEmail = $('#ConfirmEmail').val(); var password = $('#password').val(); var ConfirmPassword = $('#ConfirmPassword').val(); var ExtraWord = $('#ExtraWord').val(); var QuestionNo = $('#QuestionNo').val(); var UserAnswer = $('#UserAnswer').val(); //SK added to remove <> from password - set focus on password for formtip var iChars = '<>'; for (var i = 0; i < password.length; i++) { if (iChars.indexOf(password.charAt(i)) != -1) { $('#password').val(''); $('#ConfirmPassword').val(''); $('#password').focus(); $('#strength span').removeClass(); return false; } } for (var i = 0; i < ConfirmPassword.length; i++) { if (iChars.indexOf(ConfirmPassword.charAt(i)) != -1) { $('#ConfirmPassword').val(''); $('#ConfirmPassword').focus(); return false; } } for (var i = 0; i < ExtraWord.length; i++) { if (iChars.indexOf(ExtraWord.charAt(i)) != -1) { $('#ExtraWord').val(''); $('#ExtraWord').focus(); return false; } } for (var i = 0; i < UserAnswer.length; i++) { if (iChars.indexOf(UserAnswer.charAt(i)) != -1) { $('#UserAnswer').val(''); $('#UserAnswer').focus(); return false; } } if (isvalid) { var ent = 0; var sync = 0; var bby = 0; var keytype = $('#keytype'); if(keytype.val().length != 0) { // SUBMIT $('#signupform').submit(); } else { // CHECK KEYCODE uber.reg.checkKeycode(); } } }, checkKeycode: function() { $('#Register').before('

' + ls.text_checkingKeycode + '

').addClass('disabled'); var Key = $.trim($('#KeyCode').val()); $('#ent').val('0'); $('#reg').val('0'); $.ajax({ url: psURLPrefix + psGoSite + 'my.webrootanywhere.com/aboutkey.aspx?K=' + Key, type: 'GET', success: function (data) { //console.log('SUCCESS', data); $('#Register').removeClass('disabled') $('#checkingkeycode').remove(); if (data.indexOf('Error') == -1) { var n = data.split(","); ent = n[0]; sync = n[1]; bby = n[2]; // IF BUSINESS OR BACKUP AND SYNC PRESENT, OFFER TERMS OR REGION OPTION if (ent == 1 || sync == 1) { if (ent == 1) { $('#ent').val('1'); $('#dterms').removeClass('hidden'); $('#keytype').val('business'); $('#Register').val(ls.text_agreeandregister); //$('#Terms').removeAttr('allowblank'); } //if sync on key, no region - ask //if sync on key and best buy - ask regardless of region as creating new console if (sync == 1) { $('#reg').val('1'); $('#dregion').show(); $('#Region').removeAttr('allowblank'); $('#keytype').val('complete'); } return false; } else { // NORMAL KEYCODE (e.g. AV), THEREFORE NO NEED FOR TERMS OR REGION $('#ent').val('0'); $('#dterms').addClass('hidden'); $('#Register').val(ls.text_register); $('#dregion').hide(); $('#signupform').submit(); } } else { // KEYCODE INVALID $('#KeyCode').addClass('fielderror').after('

' + ls.text_keycodeinvalid + '

') } } }); }, setFormTips: function() { // IF FORMTIP DOESN'T EXIST - APPEND TO BODY var formtip = $('.formtip'); if(formtip.length == 0) { $('body').append(''); formtip = $('.formtip'); }; // HERE IS THE LIST OF FIELDS TO CHECK ON EACH PAGE var fields = { '#KeyCode': ls.psMessage114, '#Email': ls.psMessage115, '#ConfirmEmail': ls.psMessage116, '#password': ls.psMessage117, '#NewPassword': ls.psMessage117, '#CurrentPassword': ls.text_entercurrentpassword, '#CCurrentPassword': ls.text_entercurrentpassword, '#ConfirmPassword': ls.psMessage118, '#PreviousKeyCode': ls.psMessage119, '#QuestionNo': ls.psMessage120, '#QuestionNo2': ls.psMessage120, '#QuestionNo3': ls.psMessage120, '#UserAnswer': ls.psMessage121, '#UserAnswer2': ls.psMessage121, '#UserAnswer3': ls.psMessage121, '#SecurityAnswer': ls.text_thisiscasesensitive, '#ExtraWord': ls.psMessage123 }; // SPECIFIC JAPANESE STRING if(psLangSite == 'ja-') { fields['#ExtraWord'] = ls.psMessage122; }; // DIFFERENT LANGSTRING FOR FORGOTPASSWORD PAGE if(window.location.pathname == '/forgotpassword.aspx') { fields['#Email'] = ls.text_formtip_emailorphone; }; // LOOP THROUGH EACH FIELD AND APPLY THE RESPECTIVE FORMTIP ATTRIBUTE // IF ATTRIBUTE ALREADY EXISTS - DONT REPLACE $.each(fields, function(id, text) { var field = $(id); if(field.length > 0) { var attrDoesntExist = field.attr('data-formtip') == undefined; if(attrDoesntExist) { field.attr('data-formtip', text); }; }; }); /* OLD WAY! // APPLY ALL FORMTIP ATTRIBUTES $('#KeyCode').attr('data-formtip', ls.psMessage114); $('#Email').attr('data-formtip', ls.psMessage115); //$('#EmailAddress').attr('data-formtip', ls.psMessage115); $('#ConfirmEmail').attr('data-formtip', ls.psMessage116); $('#password').attr('data-formtip', ls.psMessage117); $('#NewPassword').attr('data-formtip', ls.psMessage117); $('#CurrentPassword').attr('data-formtip', ls.text_entercurrentpassword); $('#CCurrentPassword').attr('data-formtip', ls.text_entercurrentpassword); $('#ConfirmPassword').attr('data-formtip', ls.psMessage118); $('#PreviousKeyCode').attr('data-formtip', ls.psMessage119); $('#QuestionNo').attr('data-formtip', ls.psMessage120); $('#UserAnswer').attr('data-formtip', ls.psMessage121); $('#SecurityAnswer').attr('data-formtip', ls.text_thisiscasesensitive); if (psLangSite == 'ja-') { $('#ExtraWord').attr('data-formtip', ls.psMessage122); } else { $('#ExtraWord').attr('data-formtip', ls.psMessage123); } */ }, positionFormtip: function(el) { //console.log('positionFormtip', el); var ftip = $('.formtip'); if(ftip.length > 0) { var t = $(el); var w = t.outerWidth(); var txt = t.attr('data-formtip'); // UPDATE FORMTIP AND SHOW ftip.html('' + txt).addClass('show').css({ width: w }); // MEASURE HEIGHT OF FORMTIP NOW CONTENT AND WIDTH HAVE BEEN SET var offset = t.offset(); var a = offset.top; var b = 10; var c = ftip.outerHeight(); var h = a - b - c; // POSITION TOOLTIP TAKING INTO ACCOUNT THE HEIGHT OF THE TOOLTIP ftip.css({ top: h, left: offset.left }); } } }; // *********************************************************************** // INITIALIZE REGISTRATION VALIDATION // *********************************************************************** $(document).ready(function () { uber.reg.init(); });